//
//  AddressCell.m
//  PPDL
//
//  Created by 王洋 on 2019/7/24.
//  Copyright © 2019 王洋. All rights reserved.
//

#import "AddressCell.h"

@interface AddressCell ()

@property (weak, nonatomic) IBOutlet UILabel *addressName;
@property (weak, nonatomic) IBOutlet UILabel *addressPCA;

@property (weak, nonatomic) IBOutlet UIButton *btnDefault;

@property (weak, nonatomic) IBOutlet UIView *bgView;


@end

@implementation AddressCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

        [self.btnDefault pp_clipCorners:UIRectCornerAllCorners radius:3];
    });


}

- (void)fillCellWithModel:(AddressItemModel *)model {
    
    self.model = model;
    self.addressName.text = [NSString stringWithFormat:@"%@      %@",model.userName, model.phone];
    self.addressPCA.text = [NSString stringWithFormat:@"%@-%@-%@-%@",model.province,model.city,model.area,model.address];
    
    if (model.isDefault == 1) {  //默认    按钮选中   tag显示

        self.btnDefault.hidden = NO;

    } else {  //非默认     选中取消   tag不显示
        
        self.btnDefault.hidden = YES;
    }
    

}
- (IBAction)deleteAddress:(id)sender {
    
    if (self.deleteBtnClickBlock) {
        self.deleteBtnClickBlock(self.model);
    }
}

- (IBAction)editAddress:(id)sender {
    
    if (self.editBtnClickBlock) {
        self.editBtnClickBlock(self.model);
    }
}

- (IBAction)addressDefaultClick:(id)sender {
    
    self.model.isDefault = !self.model.isDefault;
    
    [self.btnDefault setImage:self.model.isDefault?[UIImage imageNamed:@"admire_bg"]:[UIImage imageNamed:@"empty_bg"]
                     forState:UIControlStateNormal];
    
    if (self.refreshItemModel) {
        self.refreshItemModel(self.model);
    }
}




@end
